package cn.iocoder.yudao.module.infra.repository.mybatis.dao.logger;

import cn.iocoder.yudao.common.pojo.PageResult;
import cn.iocoder.yudao.core.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.core.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.infra.repository.mybatis.domain.logger.ApiErrorLog;
import cn.iocoder.yudao.module.infra.vo.logger.apierrorlog.ApiErrorLogExportReqVO;
import cn.iocoder.yudao.module.infra.vo.logger.apierrorlog.ApiErrorLogPageReqVO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * API 错误日志 Mapper
 */
@Mapper
public interface ApiErrorLogMapper extends BaseMapperX<ApiErrorLog> {

    default PageResult<ApiErrorLog> selectPage(ApiErrorLogPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ApiErrorLog>()
                .eqIfPresent(ApiErrorLog::getUserId, reqVO.getUserId())
                .eqIfPresent(ApiErrorLog::getUserType, reqVO.getUserType())
                .eqIfPresent(ApiErrorLog::getApplicationName, reqVO.getApplicationName())
                .likeIfPresent(ApiErrorLog::getRequestUrl, reqVO.getRequestUrl())
                .betweenIfPresent(ApiErrorLog::getExceptionTime, reqVO.getExceptionTime())
                .eqIfPresent(ApiErrorLog::getProcessStatus, reqVO.getProcessStatus())
                .orderByDesc(ApiErrorLog::getId)
        );
    }

    default List<ApiErrorLog> selectList(ApiErrorLogExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ApiErrorLog>()
                .eqIfPresent(ApiErrorLog::getUserId, reqVO.getUserId())
                .eqIfPresent(ApiErrorLog::getUserType, reqVO.getUserType())
                .eqIfPresent(ApiErrorLog::getApplicationName, reqVO.getApplicationName())
                .likeIfPresent(ApiErrorLog::getRequestUrl, reqVO.getRequestUrl())
                .betweenIfPresent(ApiErrorLog::getExceptionTime, reqVO.getExceptionTime())
                .eqIfPresent(ApiErrorLog::getProcessStatus, reqVO.getProcessStatus())
                .orderByDesc(ApiErrorLog::getId)
        );
    }

}
